package com.pignest.hotel.beans;

import java.util.Date;
import java.util.Set;

import com.pignest.hotel.annotation.Bean;
import com.pignest.hotel.beans.global.BaseBean;
import com.pignest.hotel.definition.BookingStatus;
import com.pignest.hotel.util.DateUtil;


/** 客户预订 */
@Bean("预订")
public class Booking extends BaseBean {
	private static final long serialVersionUID = 1214318959422295837L;
	
	/** 预计状态 
	 * @see BookingStatus */
	private String status;
	/** 预订者 */
	private String name;
	/** 预订者电话 */
	private String phone;
	/** 预订时间 */
	private Date time;
	/** 预订的开始时间, 到达时间 */
	private Date estimatedTime;
	/** 保留时间, 以分钟为单位 */
	private int preserve;
	/** 结束时间, 取消时间 */
	private Date endTime;
	/** 备注, 其它说明 */
	private String remark;
	/** 预订离开时间 */
	private Date leaveTime;
	
	/** 排房数量 */
	private int reserved;
	
	/** 预订会员 */
	private Member member;
	
	private Set<BookingRoom> bookingRooms;
	
	
	public int getPreserve() {
		return preserve;
	}
	public void setPreserve(int duration) {
		this.preserve = duration;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public Date getEstimatedTime() {
		return estimatedTime;
	}
	public void setEstimatedTime(Date startTime) {
		this.estimatedTime = startTime;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public int getReserved() {
		return reserved;
	}
	
	public void setReserved(int reserved) {
		this.reserved = reserved;
	}
	
	public String getStatus() {
		return status;
	}
	
	public void setStatus(String status) {
		this.status = status;
	}
	
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	
	public Date getEndTime() {
		return endTime;
	}
	
	public Member getMember() {
		return member;
	}
	
	public void setMember(Member member) {
		this.member = member;
	}
	
	public Set<BookingRoom> getBookingRooms() {
		return bookingRooms;
	}
	
	public void setBookingRooms(Set<BookingRoom> bookingRooms) {
		this.bookingRooms = bookingRooms;
	}
	
	public void setLeaveTime(Date leaveTime) {
		this.leaveTime = leaveTime;
	}
	
	public Date getLeaveTime() {
		return leaveTime;
	}
	
	//////////////////////////////////////////////////////////////
	
	public String getBookingStatus() {
		return BookingStatus.displayName(status);
	}
	
	public String getLeaveTimeLabel() {
		return (String) (leaveTime == null ? null : DateUtil.toString(leaveTime));
	}
	
	public String getEndTimeLabel() {
		return (String) (endTime == null ? null : DateUtil.toString(endTime, DateUtil.HOTEL_DEFAULT_FORMAT));
	} 
	 
	public String getEstimatedTimeLabel() {
		return (String) (estimatedTime == null ? null : DateUtil.toString(estimatedTime, DateUtil.HOTEL_DEFAULT_FORMAT));
	}
	
	public String getBookingRoomNames() {
		if (bookingRooms == null || bookingRooms.isEmpty())
			return "未排房";
		if (bookingRooms.size() == 1)
			return bookingRooms.iterator().next().getRoom().getName();
		StringBuilder sb = new StringBuilder();
		Set<BookingRoom> bookingRooms = this.bookingRooms;
		boolean b = true;
		for (BookingRoom bookingRoom : bookingRooms) {
			if (!b) {
				sb.append(',');
			} else {
				b = false;
			}
//			System.out.println("**********"+bookingRoom.getRoom().getName());
			sb.append(bookingRoom.getRoom().getName());
		}
		System.out.println("sb.toString()"+sb.toString());
		return sb.toString();
	}
	
	@Override
	public String toSimpleString() {
		return concat(name, phone);
	}
}
